***children's dataset


use "/Users/Amit/OneDrive - Center for Disease Dynamics, Economics & Policy/Ongoing projects/NFHS-5 Research/Dataset/Raw Files/nfhs5_child.DTA", clear
********Demographic Variables **********

rename (v001 v002 b16 b4 v201 ) (cluster hh_id child_no sex_child total_children)


**** State Divide into Region**********

gen region = 1 if (v024 == 1 | v024 ==2 | v024 ==3| v024 ==4| v024 ==5 | v024 ==6| v024 ==7| v024 ==8|v024 == 37)
replace region =2 if (v024 == 9 | v024 ==22 | v024 ==23)
replace region =3 if (v024 == 10 | v024 ==19 | v024 ==20 | v024 == 21)
replace region =4 if (v024 == 12 | v024 ==18 | v024 ==14 | v024 == 17 | v024 == 15 | v024 ==13| v024 ==16|v024  ==  11)
replace region =5 if (v024 == 25 | v024 ==26 | v024 ==30 | v024 == 24 | v024 == 27 )
replace region =6 if (v024 == 35 | v024 ==28 | v024 ==29 | v024 == 32 | v024 == 31 |v024 == 33| v024 ==34 |v024 ==36)
ta v024 region
label define region 1"North" 2"Central" 3"East" 4"NorthEast" 5"West" 6"South"
label values region region

**********For Date of Interview********

gen doi_cdc = v008a - 21916
format %td doi_cdc

gen doi=v008a

**CMC format ***********

egen doi_cmc = convertCMC(v008), day(v016)


******Phase*********
gen phase = 1 if  inlist(v024, 1,2, 10, 13, 11, 14, 15, 16, 17, 18, 19, 24, 25, 27, 28, 29, 30, 31, 32, 35, 36, 37)
replace phase = 2 if phase == .

*Other ******
recode bord (1 = 1) (2=2)(3=3) ( 4/16=4 "4 or greater") , gen(bord_cat)
ren v130 religion 
recode religion  ( 1=1 "Hindu") ( 2 = 2 "Muslim") ( 3 = 3 "Sikh" ) (4= 4 "Christian" ) ( 5 6 7 8 9 96 = 5 "Other"), gen(religion_cat1)
recode religion  ( 1=1 "Hindu") ( 2 = 2 "Muslim") ( 3 4 5 6 7 8 9 96 = 3 "Other"), gen(religion_cat)
ren s116 caste
recode caste (1 =1 "SC") ( 2 = 2 "ST") ( 3 = 3 "OBC") (4 8 . = 4 "Other"), gen(caste_cat)
recode v151 (1 =1 "Male") ( 2 = 2 "Female") ( 3 = . ), gen(head_sex)

*******/////////////////  converting transgender data in to missing***************

ren v152 head_age
ren v025 place_residence
ren v024 state
ren sdist district
ren v190 wealth_index
recode m15  (11 12 13 96 = 1 " Non-Institutional ") ( 21/33 = 2 " Institutional") , gen(place_delivery)
ren m17 del_caesarean
ren m1 tetanusinj_beforebirth
ren m14 no_ancvisit_pregnancy
ren v106 respondent_edu 
ren v012 respondent_age

gen hh_size = 1 if v136 <=4
replace hh_size = 2 if v136 >4 & v136<.
*captailized below label
label define hh_size 1"Less than 4" 2"More than 4"
label value hh_size hh_size

recode v501 ( 0 = 1 "Not married/gauna performed") (1 = 2 "Married") (3 4 5 = 3 "Widowed/divorsed/seprated") , gen(marital_status)

recode v501 ( 0 3 4 5 = 1 "Not married/gauna performed/Widowed/divorsed/seprated") (1 = 2 "Married")  , gen(marital_status_cat)
********/// converting unmarried and widow into one coding ******

recode v208 (0= 0 "No births") (1 = 1 "1 Births") (2= 2 "2 Births") (3 4 5 = 3 " 3 Births and more"), gen(live_births)



************Child's Characteristics *************


*****Children's age in CDC format******

gen child_dob = b18 - 21916
format %td child_dob

ren b18 child_dob_cdc

gen child_agedays = doi-child_dob_cdc
gen child_agemonth = b19
gen child_ageyears = child_agemonth /12
gen child_ageweeks = child_agedays /7

*added recode of following variables 
recode child_agemonth (0/3=1 "Less than 3") (4/6=2 "3 to 6") (6/12=3 "6 to 12" ) (12/60=4 "Older than 12 months" ), gen(child_agemonth_cat)
recode head_age (0/21=1 "Under 21") (21/31=2 "21 to 31") (31/41=3 "31 to 41" ) (41/100=4 "Older than 41" ), gen(head_age_cat)


************Non vaccination variable************8



**********Height & weight ********
gen respondent_weight = v437/10
replace respondent_weight = . if v437 == 9994 | v437 == 9995 | v437 == 9996

gen respondent_height = v438/1000
replace respondent_height = . if v438== 9994 | v438 == 9995 | v438 == 9996

gen respondent_bmi = (respondent_weight / (respondent_height ^2))

summ respondent_bmi , detail
gen respond_bmi_cat =  1 if respondent_bmi < 18.5
replace respond_bmi_cat = 2 if respondent_bmi >=18.5 & respondent_bmi <25 & respond_bmi_cat ==.
replace respond_bmi_cat =  3 if respondent_bmi >=25 & respondent_bmi <30
replace respond_bmi_cat = 4 if respondent_bmi >= 30 & respondent_bmi !=.



ren m19 child_birthweight
replace child_birthweight=. if child_birthweight>=9998

*** Variable: BODY WEIGHT (KILOGRAMS) ***
codebook hw2, tab (10000)
gen	child_weight = hw2/10 
	//We divide it by 10 in order to express it in kilograms 	//Missing values are 994 to 996
replace child_weight = . if hw2 == 9994 | hw2 == 9995 | hw2 == 9996
	//All missing values or out of range are replaced as "."
desc child_weight 
summ child_weight


*** Variable: HEIGHT (CENTIMETERS)
codebook hw3, tab (10000)
gen	child_height = hw3/10 
	//We divide it by 10 in order to express it in centimeters	//Missing values are 9994 to 9996
replace child_height = . if hw3== 9994 | hw3 == 9995 | hw3 == 9996
	//All missing values or out of range are replaced as "."
desc child_height 
summ child_height


************* Anthropometry indicators **********
gen wt=v005/1000000

//Severely stunted
gen ch_sev_stunt= 0
replace ch_sev_stunt=. if hw70>=9996
replace ch_sev_stunt=1 if hw70<-300 
label define ch_sev_stunt 1"yes" 0 "no"
label value ch_sev_stunt ch_sev_stunt
label var ch_sev_stunt "Severely stunted child under 5 years"

//Stunted
gen ch_stunt= 0
replace ch_stunt=. if hw70>=9996
replace ch_stunt=1 if hw70<-200 
label define ch_stunt 1"yes" 0 "no"
label value ch_stunt ch_stunt
label var ch_stunt "Stunted child under 5 years"

//Mean haz
gen haz=hw70/100 if hw70<996
summarize haz[iw=wt]
gen ch_mean_haz=round(r(mean),0.1)
label var ch_mean_haz "Mean z-score for height-for-age for children under 5 years"

//Severely wasted 
gen ch_sev_wast= 0
replace ch_sev_wast=. if hw72>=9996
replace ch_sev_wast=1 if hw72<-300
label define ch_sev_wast 1"yes" 0 "no"
label value ch_sev_wast ch_sev_wast
label var ch_sev_wast "Severely wasted child under 5 years"

//Wasted
gen ch_wast= 0
replace ch_wast=. if hw72>=9996
replace ch_wast=1 if hw72<-200  
label define ch_wast 1"yes" 0 "no"
label value ch_wast ch_wast
label var ch_wast "Wasted child under 5 years"

//Overweight for height
gen ch_ovwt_ht= 0
replace ch_ovwt_ht=. if hw72>=9996
replace ch_ovwt_ht=1 if hw72>200 & hw72<9996 
label define ch_ovwt_ht 1"yes" 0 "no"
label value ch_ovwt_ht ch_ovwt_ht
label var ch_ovwt_ht "Overweight for height child under 5 years"

//Mean whz
gen whz=hw72/100 if hw72<996
summarize whz[iw=wt]
gen ch_mean_whz=round(r(mean),0.1)
label var ch_mean_whz "Mean z-score for weight-for-height for children under 5 years"

//Severely underweight
gen ch_sev_underwt= 0
replace ch_sev_underwt=. if hw71>=9996
replace ch_sev_underwt=1 if hw71<-300
label define ch_sev_underwt 1"yes" 0 "no"
label value ch_sev_underwt ch_sev_underwt
label var ch_sev_underwt	"Severely underweight child under 5 years"

//Underweight
gen ch_underwt= 0
replace ch_underwt=. if hw71>=9996
replace ch_underwt=1 if hw71<-200 
label define ch_underwt 1"yes" 0 "no"
label value ch_underwt ch_underwt
label var ch_underwt "Underweight child under 5 years"

//Overweight for age
gen ch_ovwt_age= 0
replace ch_ovwt_age=. if hw71>=9996
replace ch_ovwt_age=1 if hw71>200 & hw71<9996 
label define ch_ovwt_age 1"yes" 0 "no"
label value ch_ovwt_age ch_ovwt_age
label var ch_ovwt_age "Overweight for age child under 5 years"

//Mean waz
gen waz=hw71/100 if hw71<996
summarize waz[iw=wt]
gen ch_mean_waz=round(r(mean),0.1)
label var ch_mean_waz "Mean weight-for-age for children under 5 years"

*** Anemia indicators ***

//Any anemia
gen ch_any_anem=0 if   hw1>5 & hw1<60
replace ch_any_anem=1 if hw57<110  & hw1>5 & hw1<60
replace ch_any_anem=. if hw57==.
label define ch_any_anem 1"yes" 0 "no"
label value ch_any_anem ch_any_anem
label var ch_any_anem "Any anemia - child 6-59 months"

//Mild anemia
gen ch_mild_anem=0 if   hw1>5 & hw1<60
replace ch_mild_anem=1 if hw57>99 & hw57<110 & hw1>5 & hw1<60
replace ch_mild_anem=. if hw57==.
label define ch_mild_anem 1"yes" 0 "no"
label value ch_mild_anem ch_mild_anem
label var ch_mild_anem "Mild anemia - child 6-59 months"

//Moderate anemia
gen ch_mod_anem=0 if  hw1>5 & hw1<60
replace ch_mod_anem=1 if hw57>69 & hw57<100 & hw1>5 & hw1<60
replace ch_mod_anem=. if hw57==.
label define ch_mod_anem 1"yes" 0 "no"
label value ch_mod_anem ch_mod_anem
label var ch_mod_anem "Moderate anemia - child 6-59 months"

//Severe anemia
gen ch_sev_anem=0 if   hw1>5 & hw1<60
replace ch_sev_anem=1 if hw57<70 & hw1>5 & hw1<60
replace ch_sev_anem=. if hw57==.
label define ch_sev_anem 1"yes" 0 "no"
label value ch_sev_anem ch_sev_anem
label var ch_sev_anem "Severe anemia - child 6-59 months"



***********Over all variable for stunting , wasting ********

gen stunting = 1 if hw70 <-300 
replace stunting = 2 if hw70 >=-300 & hw70<-200
replace stunting = 3 if hw70 >=-200 & hw70<=200
replace stunting = 4 if hw70 >200 & hw70<9996
label define stunting 1 "Severly stunted" 2"Moderate Stunted" 3"Normal" 4"Over height for age"
label value stunting stunting

gen wasting = 1 if hw72 <-300
replace wasting = 2 if hw72 >=-300 & hw72<-200
replace wasting = 3 if hw72 >=-200 & hw72<=200
replace wasting = 4 if hw72 >200 & hw72<9996
label define wasting 1 "Severly wasted" 2"Moderate Wasted" 3"Normal" 4"Overweight for age"
label value wasting wasting

gen underweight = 1 if hw71 <-300
replace underweight = 2 if hw71 >=-300 & hw71<-200
replace underweight = 3 if hw71 >=-200 & hw71<=200
replace underweight = 4 if hw71 >200 & hw71<9996
label define underweight 1 "Severly underweight" 2"Moderate underweight" 3"Normal" 4"Overweight for age"
label value underweight underweight




******* Mortality *********

codebook b5, tab (10)	
gen child_died = 1 if b5==0
	//Redefine the coding and labels (1=child dead; 0=child alive)
replace child_died = 0 if b5==1
replace child_died = . if b5==.
label define lab_died 1 "child has died" 0 "child is alive"
label values child_died lab_died
tab b5 child_died, miss

rename v003 mother_no
rename hw19 date_measured //year
rename v007 interview_year
**4 & 5 is smaller than average and very smaller than average
g birth_outcome2=1 if m18>=4 & m18<=5
replace birth_outcome2=0 if  m18>=1 & m18<=3
rename m18 birth_size
replace birth_size=. if birth_size>=7
 rename b2 birth_year
 g age_death_months= b7
g age_death= b6
******z scores
gen zscore_outcome1= hw70/100 if hw70<600 & hw70>-600
gen zscore_outcome2= hw70/100 if hw70<600 & hw70>-600

gen height_for_age_z=hw70/100 if hw70<600 & hw70>-600
gen weight_for_height_z=hw72/100 if hw72<600 & hw72>-600

gen round=5


save "/Users/Amit/OneDrive - Center for Disease Dynamics, Economics & Policy/NFHS-5 Research/Dataset/Generated/child_clean.dta", replace
